<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>供应商列表</title>
    <link rel="stylesheet" href="../../../css/style.css">
    <!--    &lt;!&ndash; 引入JQuery JS 文件 &ndash;&gt;-->
    <!--    <script src="../../../assets/js/jquery-3.7.1.min.js"></script>-->
    <!--    &lt;!&ndash; 引入 Bootstrap CSS 文件 &ndash;&gt;-->
    <!--    <link rel="stylesheet" href="../../../assets/css/bootstrap.min.css">-->
    <!--    &lt;!&ndash; 引入 Bootstrap JS 文件 &ndash;&gt;-->
    <!--    <script src="../../../assets/js/bootstrap.bundle.min.js"></script>-->

    <!-- 引入 jQuery-->
    <script src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <!-- 引入 Axios -->
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

    <style>
        /* 复制material_list.html的样式 */
        .submenu { display: none; }
        .menu-item.active > .submenu { display: block; }
        .menu-arrow { transition: transform 0.2s; }
        .menu-item.active > a > .menu-arrow { transform: rotate(90deg); }
        .table th { background-color: #f8f9fa; }
        .submenu li a.active { color: #28a745; font-weight: bold; transform: translateY(2px); display: inline-block; }
        .search-area { background: #f8f9fa; padding: 10px; border-radius: 8px; margin: 10px 0; width: 100%; }
        .search-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
        .search-item { flex: 0 0 auto; margin-right: 10px; margin-bottom: 5px; }
        .search-item .form-control, .search-item .form-select { width: 120px; height: 31px; font-size: 14px; }
        .search-item .btn { padding: 4px 8px; }
        .search-label { display: block; margin-bottom: 5px; font-size: 14px; color: #555; white-space: nowrap; }
        .table-responsive { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
        .custom-table { width: 100%; border-collapse: separate; border-spacing: 0; }
        .custom-table th { background: #f8f9fa; color: #495057; font-weight: 600; padding: 12px 15px; border-bottom: 2px solid #dee2e6; white-space: nowrap; }
        .custom-table td { padding: 12px 15px; border-bottom: 1px solid #eee; vertical-align: middle; }
        .action-buttons { display: flex; gap: 8px; }
        .action-buttons .btn {
            padding: 4px 10px;
            font-size: 13px;
            min-width: 60px;
            white-space: nowrap;
        }
        .page-title { font-size: 22px; font-weight: 600; margin-bottom: 20px; color: #333; display: flex; align-items: center; gap: 10px; }
        .page-title-icon { font-size: 24px; }
        .ms-auto { margin-left: auto; }
        .add-button { padding: 8px 16px; display: flex; align-items: center; gap: 5px; font-weight: 500; }
        .content-wrapper { padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin: 20px; }

        /* 表单验证样式 */
        .invalid-feedback {
            display: block;
            width: 100%;
            margin-top: 0.25rem;
            font-size: 0.875em;
            color: #dc3545;
        }
        .form-control.is-invalid, .form-select.is-invalid {
            border-color: #dc3545;
            padding-right: calc(1.5em + 0.75rem);
            background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right calc(0.375em + 0.1875rem) center;
            background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
        }
        .form-select.is-invalid {
            background-position: right 0.75rem center, center right 2.25rem;
            background-size: 16px 12px, calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
        }
        .form-control.is-invalid:focus, .form-select.is-invalid:focus {
            border-color: #dc3545;
            box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
        }

        /* iOS风格模态框样式 */
        .modal.ios-style {
            background: rgba(0, 0, 0, 0.4);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
        }

        .modal.ios-style .modal-dialog {
            max-width: 500px;
            margin: 1.75rem auto;
            display: flex;
            align-items: center;
            min-height: calc(100% - 3.5rem);
        }

        .modal.ios-style .modal-content {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-radius: 20px;
            border: none;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
            overflow: hidden;
        }

        .modal.ios-style .modal-header {
            padding: 20px 20px 10px;
            text-align: center;
            border-bottom: 1px solid rgba(0, 0, 0, 0.1);
            position: relative;
        }

        .modal.ios-style .modal-title {
            font-size: 18px;
            font-weight: 600;
            color: #333;
            width: 100%;
            text-align: center;
        }

        .modal.ios-style .btn-close {
            position: absolute;
            right: 20px;
            top: 50%;
            transform: translateY(-50%);
            background: none;
            opacity: 0.5;
            transition: opacity 0.2s;
        }

        .modal.ios-style .btn-close:hover {
            opacity: 1;
        }

        .modal.ios-style .modal-body {
            padding: 20px;
            max-height: 60vh;
            overflow-y: auto;
        }

        .modal.ios-style .form-label {
            font-weight: 500;
            color: #666;
            font-size: 14px;
            margin-bottom: 8px;
        }

        .modal.ios-style .form-control,
        .modal.ios-style .form-select {
            border-radius: 12px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            padding: 10px 15px;
            font-size: 15px;
            transition: all 0.2s;
        }

        .modal.ios-style .form-control:focus,
        .modal.ios-style .form-select:focus {
            border-color: #007AFF;
            box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
        }

        .modal.ios-style .modal-footer {
            padding: 15px 20px 20px;
            border-top: 1px solid rgba(0, 0, 0, 0.1);
            justify-content: center;
            gap: 10px;
        }

        .modal.ios-style .btn {
            border-radius: 12px;
            padding: 10px 25px;
            font-size: 15px;
            font-weight: 500;
            transition: all 0.2s;
        }

        .modal.ios-style .btn-success {
            background: #007AFF;
            border: none;
        }

        .modal.ios-style .btn-success:hover {
            background: #0056CC;
        }

        .modal.ios-style .btn-danger {
            background: #E5E5EA;
            border: none;
            color: #333;
        }

        .modal.ios-style .btn-danger:hover {
            background: #D1D1D6;
        }

        /* 滚动条样式 */
        .modal.ios-style .modal-body::-webkit-scrollbar {
            width: 4px;
        }

        .modal.ios-style .modal-body::-webkit-scrollbar-track {
            background: transparent;
        }

        .modal.ios-style .modal-body::-webkit-scrollbar-thumb {
            background: rgba(0, 0, 0, 0.2);
            border-radius: 2px;
        }
        
        /* iOS风格供应商详情模态框 */
        .ios-modal {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.4);
            backdrop-filter: blur(10px);
            -webkit-backdrop-filter: blur(10px);
            display: none;
            justify-content: center;
            align-items: center;
            z-index: 1050;
            opacity: 0;
            transition: opacity 0.3s ease;
        }
        .ios-modal.show {
            display: flex;
            opacity: 1;
        }
        .ios-modal-content {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(20px);
            -webkit-backdrop-filter: blur(20px);
            border-radius: 20px;
            padding: 0;
            max-width: 400px;
            width: 90%;
            max-height: 80vh;
            overflow: hidden;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
            transform: scale(0.8);
            transition: transform 0.3s ease;
        }
        .ios-modal.show .ios-modal-content {
            transform: scale(1);
        }
        .ios-modal-header {
            padding: 20px 20px 10px;
            text-align: center;
            border-bottom: 1px solid rgba(0, 0, 0, 0.1);
        }
        .ios-modal-title {
            font-size: 18px;
            font-weight: 600;
            color: #333;
            margin: 0;
        }
        .ios-modal-body {
            padding: 20px;
            max-height: 60vh;
            overflow-y: auto;
        }
        .ios-detail-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 0;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        }
        .ios-detail-item:last-child {
            border-bottom: none;
        }
        .ios-detail-label {
            font-weight: 500;
            color: #666;
            font-size: 14px;
        }
        .ios-detail-value {
            font-weight: 400;
            color: #333;
            font-size: 14px;
            text-align: right;
            max-width: 60%;
            word-wrap: break-word;
        }
        .ios-modal-footer {
            padding: 15px 20px 20px;
            text-align: center;
        }
        .ios-close-btn {
            background: #007AFF;
            color: white;
            border: none;
            border-radius: 12px;
            padding: 12px 30px;
            font-size: 16px;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.2s ease;
        }
        .ios-close-btn:hover {
            background: #0056CC;
        }
        .ios-modal-body::-webkit-scrollbar {
            width: 4px;
        }
        .ios-modal-body::-webkit-scrollbar-track {
            background: transparent;
        }
        .ios-modal-body::-webkit-scrollbar-thumb {
            background: rgba(0, 0, 0, 0.2);
            border-radius: 2px;
        }
        
        /* 添加按钮组样式 */
        .action-button-group {
            display: flex;
            gap: 15px;
            align-items: center;
            justify-content: flex-end;
        }
        
        .action-button-group .add-button {
            padding: 8px 16px;
            display: flex;
            align-items: center;
            gap: 8px;
            font-weight: 500;
            min-width: 140px;
            justify-content: center;
        }

        /* 调整模态框宽度 */
        .modal-xl-custom {
            max-width: 95%;
            width: 1400px;
        }

        .modal-lg-custom {
            max-width: 90%;
            width: 1000px;
        }
        
        /* 改进详情模态框样式 */
        .modal.ios-style .modal-dialog.modal-lg-custom {
            max-width: 900px;
            width: 80%;
        }
        
        .modal.ios-style .modal-dialog.modal-xl-custom {
            max-width: 1300px;
            width: 90%;
        }
        
        /* 修复模态框滚动问题 */
        .modal-dialog {
            max-height: 100%;
            display: flex;
            flex-direction: column;
        }
        
        .modal-content {
            max-height: 90vh;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        
        .modal-body {
            overflow-y: auto;
            max-height: calc(90vh - 120px); /* 减去header和footer的高度 */
            padding: 15px;
        }
        
        .table-responsive {
            overflow-y: auto;
            max-height: 60vh;
        }
        
        /* 表格标题固定 */
        .records-table thead th {
            position: sticky;
            top: 0;
            background-color: #f8f9fa;
            z-index: 10;
            box-shadow: 0 1px 2px rgba(0,0,0,0.1);
        }

        /* 卡片样式增强 */
        .card {
            border-radius: 0.5rem;
            box-shadow: 0 2px 6px rgba(0,0,0,0.08);
            border: 1px solid rgba(0,0,0,0.05);
            overflow: hidden;
        }
        
        .card-header {
            background-color: rgba(0,0,0,0.02);
            border-bottom: 1px solid rgba(0,0,0,0.05);
            padding: 0.75rem 1.25rem;
        }
        
        /* 按钮美化 */
        .btn-primary {
            background-color: #007bff;
            border-color: #007bff;
        }
        
        .btn-primary:hover {
            background-color: #0069d9;
            border-color: #0062cc;
        }
        
        .btn-info {
            background-color: #17a2b8;
            border-color: #17a2b8;
            color: white;
        }
        
        .btn-info:hover {
            background-color: #138496;
            border-color: #117a8b;
            color: white;
        }
        
        /* 状态标签样式 */
        .status-badge {
            display: inline-block;
            padding: 0.25em 0.6em;
            font-size: 0.75em;
            font-weight: 600;
            line-height: 1;
            text-align: center;
            white-space: nowrap;
            vertical-align: baseline;
            border-radius: 0.25rem;
        }
        
        .status-badge.pending {
            background-color: #ffc107;
            color: #212529;
        }
        
        .status-badge.approved {
            background-color: #28a745;
            color: white;
        }
        
        .status-badge.rejected {
            background-color: #dc3545;
            color: white;
        }
        
        /* 详情卡片样式增强 */
        .detail-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 1rem;
        }
        
        .detail-item {
            margin-bottom: 0.5rem;
            padding-bottom: 0.5rem;
            border-bottom: 1px solid #f0f0f0;
        }
        
        .detail-label {
            font-weight: 500;
            color: #666;
            margin-bottom: 0.25rem;
            font-size: 0.875rem;
        }
        
        .detail-value {
            color: #333;
            line-height: 1.5;
        }
        
        .detail-value.description {
            white-space: pre-wrap;
            background: #f8f9fa;
            padding: 0.75rem;
            border-radius: 0.25rem;
            font-size: 0.875rem;
            max-height: 200px;
            overflow-y: auto;
        }

        /* 表格样式 */
        .records-table {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0;
            margin-bottom: 0;
        }
        
        .records-table th {
            background: #f8f9fa;
            color: #333;
            font-weight: 600;
            padding: 12px 15px;
            border-bottom: 2px solid #dee2e6;
            white-space: nowrap;
        }
        
        /* 表格单元格样式 */
        .records-table td {
            max-width: 300px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
            vertical-align: middle;
            padding: 10px 15px;
        }
        
        .records-table td.description-cell {
            white-space: normal;
            max-height: 80px;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
        }
        
        /* 可点击行样式 */
        .records-table tbody tr {
            cursor: pointer;
            transition: background-color 0.2s;
        }
        
        .records-table tbody tr:hover {
            background-color: rgba(0, 123, 255, 0.05);
        }
    </style>
</head>
<body>
<div class="admin-layout">
    <!-- 顶部导航栏 -->
    <header class="admin-header">
        <div class="header-left">
            <div class="logo">生产过程管理系统</div>
        </div>
        <div class="header-right">
            <span class="user-info">部门经理</span>
            <span class="user-name">
                    <script>
                        try {
                            const userInfo = localStorage.getItem('userInfo');
                            const user = JSON.parse(userInfo);
                            document.write(user.name || '未登录');
                        } catch (e) {
                            document.write('未登录');
                        }
                    </script>
                </span>
            <button class="logout-btn" onclick="logout()">退出</button>
        </div>
    </header>
    <!-- 左侧菜单 -->
    <aside class="admin-sidebar">
        <ul class="menu-list">
            <li class="menu-item">
                <a href="homepage/manager_home.html">
                    <span class="menu-icon">🏠</span>
                    <span class="menu-title">首页</span>
                </a>
            </li>
            <li class="menu-item">
                <a href="javascript:void(0)">
                    <span class="menu-icon">👥</span>
                    <span class="menu-title">人员管理</span>
                    <span class="menu-arrow"></span>
                </a>
                <ul class="submenu">
                    <li><a href="../person/person_list.html">人员列表</a></li>
                    <li><a href="../person/person_edit.html">添加人员</a></li>
                    <li><a href="../person/schedule_edit.html">编辑排班表</a></li>
                    <li><a href="../person/schedule.html">查看排班表</a></li>
                    <li><a href="../person/schedule_statistics.html">班次统计</a></li>
                </ul>
            </li>
            <li class="menu-item">
                <a href="javascript:void(0)">
                    <span class="menu-icon">📦</span>
                    <span class="menu-title">物料管理</span>
                    <span class="menu-arrow"></span>
                </a>
                <ul class="submenu">
                    <li><a href="../material/material_list.html">物料列表</a></li>
                    <li><a href="*">物料采购统计</a></li>
                </ul>
            </li>
            <li class="menu-item">
                <a href="javascript:void(0)">
                    <span class="menu-icon">⚙️</span>
                    <span class="menu-title">设备管理</span>
                    <span class="menu-arrow"></span>
                </a>
                <ul class="submenu">
                    <li><a href="../device/device_list.html">设备列表</a></li>
                    <li><a href="*">设备报修报废统计</a></li>
                </ul>
            </li>
            <li class="menu-item">
                <a href="javascript:void(0)">
                    <span class="menu-icon">📝</span>
                    <span class="menu-title">产品管理</span>
                    <span class="menu-arrow"></span>
                </a>
                <ul class="submenu">
                    <li><a href="../product/product_list.html">产品列表</a></li>
                    <li><a href="../product/editproduct_plan.html">编辑生产计划</a></li>
                    <li><a href="../product/viewproduct_plan.html">查看生产计划</a></li>
                </ul>
            </li>
            <li class="menu-item">
                <a href="javascript:void(0)">
                    <span class="menu-icon">🏢</span>
                    <span class="menu-title">供应商管理</span>
                    <span class="menu-arrow"></span>
                </a>
                <ul class="submenu">
                    <li><a href="../provider/provider_list.html" class="active">供应商列表</a></li>
                </ul>
            </li>
        </ul>
    </aside>
    <!-- 主内容区域 -->
    <main class="admin-main">
        <div class="content-wrapper">
            <div class="page-title">
                <span class="page-title-icon">🏢</span>
                <span>供应商列表</span>
                <div class="ms-auto action-button-group">
                    <button class="btn btn-info add-button" onclick="showAllApplications()">
                        <i class="fas fa-list"></i> 所有供应商申请
                    </button>
                    <button class="btn btn-warning add-button" onclick="showAllComplaints()">
                        <i class="fas fa-exclamation-circle"></i> 所有供应商投诉
                    </button>
                </div>
            </div>
            <!-- 搜索区域 -->
            <div class="search-area">
                <div class="search-row">
                    <div class="search-item">
                        <label class="search-label">供应商名称</label>
                        <input type="text" class="form-control form-control-sm" id="searchProviderName" placeholder="请输入名称">
                    </div>
                    <div class="search-item">
                        <label class="search-label">企业类型</label>
                        <select class="form-select form-select-sm" id="searchCompanyType">
                            <option value="">全部</option>
                            <option value="国有企业">国有企业</option>
                            <option value="民营企业">民营企业</option>
                            <option value="外资企业">外资企业</option>
                        </select>
                    </div>
                    <div class="search-item">
                        <label class="search-label">经理姓名</label>
                        <input type="text" class="form-control form-control-sm" id="searchManagerName" placeholder="请输入姓名">
                    </div>
                    <div class="search-item">
                        <label class="search-label">供应商评级</label>
                        <select class="form-select form-select-sm" id="searchProviderRating">
                            <option value="">全部</option>
                            <option value="1">1星</option>
                            <option value="2">2星</option>
                            <option value="3">3星</option>
                            <option value="4">4星</option>
                            <option value="5">5星</option>
                        </select>
                    </div>
                    <div class="search-item">
                        <button class="btn btn-sm btn-outline-primary" onclick="searchProviders()">🔍</button>
                    </div>
                    <div class="search-item">
                        <button class="btn btn-sm btn-outline-secondary" onclick="resetSearch()">↺</button>
                    </div>
                </div>
            </div>
            <!-- 数据表格 -->
            <div class="table-responsive">
                <table class="table table-hover table-striped custom-table mb-0">
                    <thead>
                    <tr>
                        <th>供应商名称</th>
                        <th>厂址</th>
                        <th>经理姓名</th>
                        <th>经理电话</th>
                        <th>企业类型</th>
                        <th>注册资本</th>
                        <th>员工数量</th>
                        <th>成立年份</th>
                        <th>供应商评级</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="providerTableBody">
                    <!-- 数据将通过JavaScript动态加载 -->
                    </tbody>
                </table>
            </div>
        </div>
    </main>
</div>
<!-- iOS风格供应商详情模态框 -->
<div class="ios-modal" id="providerDetailModal">
    <div class="ios-modal-content">
        <div class="ios-modal-header">
            <h5 class="ios-modal-title">供应商详情</h5>
        </div>
        <div class="ios-modal-body">
            <div class="ios-detail-item">
                <span class="ios-detail-label">供应商名称</span>
                <span class="ios-detail-value" id="detailProviderName">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">厂址</span>
                <span class="ios-detail-value" id="detailFactoryAddress">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">经理姓名</span>
                <span class="ios-detail-value" id="detailManagerName">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">经理电话</span>
                <span class="ios-detail-value" id="detailManagerPhone">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">企业类型</span>
                <span class="ios-detail-value" id="detailCompanyType">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">注册资本</span>
                <span class="ios-detail-value" id="detailRegisteredCapital">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">员工数量</span>
                <span class="ios-detail-value" id="detailEmployeeCount">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">成立年份</span>
                <span class="ios-detail-value" id="detailEstablishedYear">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">供应商评级</span>
                <span class="ios-detail-value" id="detailProviderRating">-</span>
            </div>
            <div class="ios-detail-item">
                <span class="ios-detail-label">企业简介</span>
                <span class="ios-detail-value" id="detailProfile">-</span>
            </div>
        </div>
        <div class="ios-modal-footer">
            <button class="ios-close-btn" onclick="closeProviderDetailModal()">关闭</button>
        </div>
    </div>
</div>

<!-- 申请记录模态框 -->
<div class="modal fade ios-style" id="applicationRecordsModal" tabindex="-1" aria-labelledby="applicationRecordsModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl-custom">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="applicationRecordsModalLabel">供应商申请记录</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="card mb-4">
                    <div class="card-header bg-light d-flex justify-content-between align-items-center">
                        <h6 class="mb-0">筛选条件</h6>
                    </div>
                    <div class="card-body">
                        <div class="search-area mb-0">
                            <div class="search-row">
                                <div class="search-item">
                                    <label class="search-label">供应商名称</label>
                                    <input type="text" class="form-control form-control-sm" id="appSearchProviderName" placeholder="请输入名称">
                                </div>
                                <div class="search-item">
                                    <label class="search-label">申请状态</label>
                                    <select class="form-select form-select-sm" id="appSearchStatus">
                                        <option value="">全部</option>
                                        <option value="pending">待审核</option>
                                        <option value="approved">已批准</option>
                                        <option value="rejected">已驳回</option>
                                    </select>
                                </div>
                                <div class="search-item">
                                    <button class="btn btn-sm btn-outline-primary" onclick="searchApplications()">
                                        <i class="fas fa-search"></i> 搜索
                                    </button>
                                </div>
                                <div class="search-item">
                                    <button class="btn btn-sm btn-outline-secondary" onclick="resetApplicationSearch()">
                                        <i class="fas fa-redo"></i> 重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="card">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">申请列表</h6>
                    </div>
                    <div class="card-body p-0" style="max-height: 60vh; overflow: auto;">
                        <table class="table table-hover records-table mb-0">
                            <thead>
                                <tr>
                                    <th style="width: 20%">供应商名称</th>
                                    <th style="width: 15%">企业类型</th>
                                    <th style="width: 15%">经理姓名</th>
                                    <th style="width: 20%">申请人工号</th>
                                    <th style="width: 10%">状态</th>
                                    <th style="width: 20%">操作</th>
                                </tr>
                            </thead>
                            <tbody id="applicationRecordsBody">
                                <!-- 数据将通过JavaScript动态加载 -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 投诉记录模态框 -->
<div class="modal fade ios-style" id="complaintRecordsModal" tabindex="-1" aria-labelledby="complaintRecordsModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl-custom">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="complaintRecordsModalLabel">供应商投诉记录</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body">
                <div class="card mb-4">
                    <div class="card-header bg-light d-flex justify-content-between align-items-center">
                        <h6 class="mb-0">筛选条件</h6>
                    </div>
                    <div class="card-body">
                        <div class="search-area mb-0">
                            <div class="search-row">
                                <div class="search-item">
                                    <label class="search-label">供应商名称</label>
                                    <input type="text" class="form-control form-control-sm" id="compSearchProviderName" placeholder="请输入名称">
                                </div>
                                <div class="search-item">
                                    <label class="search-label">投诉状态</label>
                                    <select class="form-select form-select-sm" id="compSearchStatus">
                                        <option value="">全部</option>
                                        <option value="pending">待审核</option>
                                        <option value="approved">已批准</option>
                                        <option value="rejected">已驳回</option>
                                    </select>
                                </div>
                                <div class="search-item">
                                    <button class="btn btn-sm btn-outline-primary" onclick="searchComplaints()">
                                        <i class="fas fa-search"></i> 搜索
                                    </button>
                                </div>
                                <div class="search-item">
                                    <button class="btn btn-sm btn-outline-secondary" onclick="resetComplaintSearch()">
                                        <i class="fas fa-redo"></i> 重置
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="card">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">投诉列表</h6>
                    </div>
                    <div class="card-body p-0" style="max-height: 60vh; overflow: auto;">
                        <table class="table table-hover records-table mb-0">
                            <thead>
                                <tr>
                                    <th style="width: 15%">供应商名称</th>
                                    <th style="width: 15%">问题材料</th>
                                    <th style="width: 30%">投诉描述</th>
                                    <th style="width: 15%">投诉人工号</th>
                                    <th style="width: 10%">状态</th>
                                    <th style="width: 15%">操作</th>
                                </tr>
                            </thead>
                            <tbody id="complaintRecordsBody">
                                <!-- 数据将通过JavaScript动态加载 -->
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 申请详情模态框 -->
<div class="modal fade ios-style" id="applicationDetailModal" tabindex="-1" aria-labelledby="applicationDetailModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg-custom">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="applicationDetailModalLabel">供应商申请详情</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body overflow-auto">
                <div class="row mb-4">
                    <div class="col-md-8">
                        <div class="detail-grid">
                            <div class="detail-item">
                                <div class="detail-label">供应商名称</div>
                                <div class="detail-value" id="appDetail-providerName">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">企业类型</div>
                                <div class="detail-value" id="appDetail-companyType">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">经理姓名</div>
                                <div class="detail-value" id="appDetail-managerName">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">经理电话</div>
                                <div class="detail-value" id="appDetail-managerPhone">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">注册资本</div>
                                <div class="detail-value" id="appDetail-registeredCapital">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">员工数量</div>
                                <div class="detail-value" id="appDetail-employeeCount">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">成立年份</div>
                                <div class="detail-value" id="appDetail-establishedYear">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">申请状态</div>
                                <div class="detail-value" id="appDetail-status">-</div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card h-100">
                            <div class="card-header bg-light">
                                <h6 class="mb-0">企业简介</h6>
                            </div>
                            <div class="card-body">
                                <div class="detail-value description" id="appDetail-profile">-</div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card mt-4" id="appDetail-reviewContainer" style="display: none;">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">审批意见</h6>
                    </div>
                    <div class="card-body">
                        <div class="detail-value description" id="appDetail-reviewDescription">-</div>
                    </div>
                </div>

                <div class="card mt-4" id="appDetail-reviewFormContainer">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">审批表单</h6>
                    </div>
                    <div class="card-body">
                        <form id="appReviewForm">
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label for="appApprovalStatus" class="form-label">处理意见: <span class="text-danger">*</span></label>
                                    <select class="form-select" id="appApprovalStatus" required>
                                        <option value="" selected disabled>请选择处理意见</option>
                                        <option value="true">审批通过</option>
                                        <option value="false">拒绝申请</option>
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label for="appInitialRating" class="form-label">初始评分: <span class="text-danger">*</span></label>
                                    <input type="number" class="form-control" id="appInitialRating" min="0" max="5" value="3" required>
                                    <small class="text-muted">0-5分，默认3分</small>
                                </div>
                            </div>
                            <div class="mb-3">
                                <label for="appDescription" class="form-label">审核意见: <span class="text-danger">*</span></label>
                                <textarea class="form-control" id="appDescription" rows="3" required></textarea>
                            </div>
                            <input type="hidden" id="appApplicationId" value="">
                            <div class="text-end">
                                <button type="button" class="btn btn-primary" onclick="submitApplicationReview()">提交审批</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 投诉详情模态框 -->
<div class="modal fade ios-style" id="complaintDetailModal" tabindex="-1" aria-labelledby="complaintDetailModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg-custom">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="complaintDetailModalLabel">供应商投诉详情</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body overflow-auto">
                <div class="row mb-4">
                    <div class="col-md-8">
                        <div class="detail-grid">
                            <div class="detail-item">
                                <div class="detail-label">供应商名称</div>
                                <div class="detail-value" id="compDetail-providerName">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">问题材料</div>
                                <div class="detail-value" id="compDetail-defectiveMaterial">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">投诉人工号</div>
                                <div class="detail-value" id="compDetail-complainant">-</div>
                            </div>
                            <div class="detail-item">
                                <div class="detail-label">投诉状态</div>
                                <div class="detail-value" id="compDetail-status">-</div>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-4">
                        <div class="card h-100">
                            <div class="card-header bg-light">
                                <h6 class="mb-0">投诉描述</h6>
                            </div>
                            <div class="card-body">
                                <div class="detail-value description" id="compDetail-description">-</div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="card mt-4" id="compDetail-reviewContainer" style="display: none;">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">审批意见</h6>
                    </div>
                    <div class="card-body">
                        <div class="detail-value description" id="compDetail-reviewDescription">-</div>
                    </div>
                </div>

                <div class="card mt-4" id="compDetail-reviewFormContainer">
                    <div class="card-header bg-light">
                        <h6 class="mb-0">审批表单</h6>
                    </div>
                    <div class="card-body">
                        <form id="compReviewForm">
                            <div class="row mb-3">
                                <div class="col-md-6">
                                    <label for="compApprovalStatus" class="form-label">处理意见: <span class="text-danger">*</span></label>
                                    <select class="form-select" id="compApprovalStatus" required>
                                        <option value="" selected disabled>请选择处理意见</option>
                                        <option value="true">审核通过</option>
                                        <option value="false">拒绝投诉</option>
                                    </select>
                                </div>
                                <div class="col-md-6">
                                    <label for="compRatingDeduction" class="form-label">供应商评级扣分: <span class="text-danger">*</span></label>
                                    <input type="number" class="form-control" id="compRatingDeduction" min="0" max="5" value="1" required>
                                    <small class="text-muted">0-5分，默认1分</small>
                                </div>
                            </div>
                            <div class="mb-3">
                                <label for="compReviewDescription" class="form-label">审核意见: <span class="text-danger">*</span></label>
                                <textarea class="form-control" id="compReviewDescription" rows="3" required></textarea>
                            </div>
                            <input type="hidden" id="compComplaintId" value="">
                            <div class="text-end">
                                <button type="button" class="btn btn-primary" onclick="submitComplaintReview()">提交审核</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>
<script src="../../assets/js/bootstrap.bundle.min.js"></script>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        var menuItems = document.querySelectorAll('.menu-item > a');
        menuItems.forEach(function (item) {
            item.addEventListener('click', function (e) {
                var parent = item.parentElement;
                document.querySelectorAll('.menu-item').forEach(function (el) {
                    if (el !== parent) el.classList.remove('active');
                });
                parent.classList.toggle('active');
                e.preventDefault();
            });
        });

        // 添加首页链接的点击事件
        document.querySelector('.menu-item:first-child > a').addEventListener('click', function (e) {
            e.preventDefault(); // 阻止默认行为
            window.location.href = '../homepage/manager_home.html'; // 跳转到管理员首页
        });

        // 默认展开供应商管理菜单
        const providerMenuItem = document.querySelector('.menu-item:nth-child(6)');
        if (providerMenuItem) {
            providerMenuItem.classList.add('active');
        }
        // 设置当前页面对应的菜单项为选中状态
        const currentPath = window.location.pathname;
        const filename = currentPath.substring(currentPath.lastIndexOf('/') + 1);
        document.querySelectorAll('.submenu li a').forEach(link => {
            if (link.getAttribute('href') === filename) {
                link.classList.add('active');
            }
        });
        // 加载供应商数据
        loadProviders();
    });

    async function loadProviders() {
        try {
            const response = await fetch('http://localhost:8080/api/providers');
            const data = await response.json();
            displayProviders(data);
        } catch (error) {
            console.error('加载供应商数据失败:', error);
            alert('加载供应商数据失败，请确保后端服务正在运行');
        }
    }

    function displayProviders(providers) {
        const tbody = document.getElementById('providerTableBody');
        tbody.innerHTML = '';

        // 添加数据验证，确保providers是数组
        if (!Array.isArray(providers)) {
            console.error('接收到的数据不是数组格式:', providers);
            tbody.innerHTML = '<tr><td colspan="10" class="text-center">无法加载数据，请检查后端服务</td></tr>';
            return;
        }

        if (providers.length === 0) {
            tbody.innerHTML = '<tr><td colspan="10" class="text-center">暂无供应商数据</td></tr>';
            return;
        }

        // 原有的遍历逻辑
        providers.forEach(provider => {
            const row = document.createElement('tr');
            row.innerHTML = `
                    <td>${provider.providerName}</td>
                    <td>${provider.factoryAddress || ''}</td>
                    <td>${provider.managerName || ''}</td>
                    <td>${provider.managerPhone || ''}</td>
                    <td>${provider.companyType || ''}</td>
                    <td>${provider.registeredCapital || 0}</td>
                    <td>${provider.employeeCount || 0}</td>
                    <td>${provider.establishedYear || ''}</td>
                    <td>${provider.providerRating || 0}</td>
                    <td>
                        <div class="action-buttons">
                            <button class="btn btn-sm btn-danger" onclick="deleteProvider('${provider.providerName}')">删除</button>
                            <button class="btn btn-sm btn-secondary" onclick="viewProviderDetail('${provider.providerName}')">详情</button>
                        </div>
                    </td>
                `;
            tbody.appendChild(row);
        });
    }

    function searchProviders() {
        const searchParams = {
            providerName: document.getElementById('searchProviderName').value.toLowerCase(),
            companyType: document.getElementById('searchCompanyType').value,
            managerName: document.getElementById('searchManagerName').value.toLowerCase(),
            providerRating: document.getElementById('searchProviderRating').value
        };
        const tbody = document.getElementById('providerTableBody');
        const rows = tbody.getElementsByTagName('tr');
        for (let row of rows) {
            const cells = row.getElementsByTagName('td');
            const rowData = {
                providerName: cells[0].textContent.toLowerCase(),
                companyType: cells[4].textContent,
                managerName: cells[2].textContent.toLowerCase(),
                providerRating: cells[8].textContent
            };
            let visible = true;
            for (const [key, value] of Object.entries(searchParams)) {
                if (value && key === 'providerRating') {
                    if (rowData[key] != value) {
                        visible = false;
                        break;
                    }
                } else if (value && !rowData[key].includes(value)) {
                    visible = false;
                    break;
                }
            }
            row.style.display = visible ? '' : 'none';
        }
    }

    function resetSearch() {
        document.getElementById('searchProviderName').value = '';
        document.getElementById('searchCompanyType').value = '';
        document.getElementById('searchManagerName').value = '';
        document.getElementById('searchProviderRating').value = '';
        const tbody = document.getElementById('providerTableBody');
        const rows = tbody.getElementsByTagName('tr');
        for (let row of rows) {
            row.style.display = '';
        }
    }

    function viewProviderDetail(providerName) {
        getProviderByName(providerName).then(provider => {
            if (provider) {
                document.getElementById('detailProviderName').textContent = provider.providerName || '-';
                document.getElementById('detailFactoryAddress').textContent = provider.factoryAddress || '-';
                document.getElementById('detailManagerName').textContent = provider.managerName || '-';
                document.getElementById('detailManagerPhone').textContent = provider.managerPhone || '-';
                document.getElementById('detailCompanyType').textContent = provider.companyType || '-';
                document.getElementById('detailRegisteredCapital').textContent = provider.registeredCapital || '-';
                document.getElementById('detailEmployeeCount').textContent = provider.employeeCount || '-';
                document.getElementById('detailEstablishedYear').textContent = provider.establishedYear || '-';
                document.getElementById('detailProviderRating').textContent = provider.providerRating || '-';
                document.getElementById('detailProfile').textContent = provider.profile || '-';
                showProviderDetailModal();
            }
        });
    }

    async function getProviderByName(providerName) {
        try {
            const response = await fetch(`http://localhost:8080/api/providers/${encodeURIComponent(providerName)}`);
            const provider = await response.json();
            return provider;
        } catch (error) {
            console.error('获取供应商详情失败:', error);
            return null;
        }
    }

    async function deleteProvider(providerName) {
        if (confirm('确定要删除这个供应商吗？')) {
            try {
                const response = await fetch(`http://localhost:8080/api/providers/${encodeURIComponent(providerName)}`, {
                    method: 'DELETE'
                });
                if (response.ok) {
                    const result = await response.json();
                    alert(result.message);
                    loadProviders();
                } else {
                    const error = await response.json();
                    alert(error.message || '删除失败');
                }
            } catch (error) {
                console.error('删除供应商时出错:', error);
                alert('删除供应商时发生错误，请稍后重试');
            }
        }
    }

    function logout() {
        localStorage.removeItem('userInfo');
        window.location.href = '../../../login.html';
    }

    // 显示iOS风格模态框
    function showProviderDetailModal() {
        const modal = document.getElementById('providerDetailModal');
        modal.classList.add('show');
        modal.onclick = function (e) {
            if (e.target === modal) {
                closeProviderDetailModal();
            }
        };
    }

    // 关闭iOS风格模态框
    function closeProviderDetailModal() {
        const modal = document.getElementById('providerDetailModal');
        modal.classList.remove('show');
    }

    // ESC键关闭模态框
    document.addEventListener('keydown', function (e) {
        if (e.key === 'Escape') {
            closeProviderDetailModal();
        }
    });
    
    // ==================== 供应商申请管理相关函数 ====================
    
    // 显示所有供应商申请
    async function showAllApplications() {
        try {
            const response = await axios.get('http://localhost:8080/api/provider/application/getApplications', {
                timeout: 5000
            });
            
            const applications = response.data;
            const tbody = document.getElementById('applicationRecordsBody');
            tbody.innerHTML = '';
            
            if (!applications || applications.length === 0) {
                tbody.innerHTML = '<tr><td colspan="6" class="text-center">暂无申请记录</td></tr>';
                return;
            }
            
            applications.forEach(app => {
                const row = document.createElement('tr');
                let statusText = '';
                let statusClass = '';
                
                if (!app.status) {
                    statusText = '待审核';
                    statusClass = 'pending';
                } else if (app.approved) {
                    statusText = '已批准';
                    statusClass = 'approved';
                } else {
                    statusText = '已驳回';
                    statusClass = 'rejected';
                }
                
                row.innerHTML = `
                    <td>${app.providerName || '-'}</td>
                    <td>${app.companyType || '-'}</td>
                    <td>${app.managerName || '-'}</td>
                    <td>${app.applicantJobNumber || '-'}</td>
                    <td><span class="status-badge ${statusClass}">${statusText}</span></td>
                    <td class="action-buttons">
                        <button class="btn btn-sm btn-info" onclick="viewApplicationDetail(${app.applicationId})">详情</button>
                        ${!app.status ? `<button class="btn btn-sm btn-primary" onclick="reviewApplication(${app.applicationId})">审批</button>` : ''}
                    </td>
                `;
                
                tbody.appendChild(row);
            });
            
            const modal = new bootstrap.Modal(document.getElementById('applicationRecordsModal'));
            modal.show();
        } catch (error) {
            console.error('加载申请记录失败:', error);
            let errorMessage = '加载申请记录失败，请稍后重试';
            if (error.response) {
                errorMessage += `（状态码: ${error.response.status}）`;
            } else if (error.request) {
                errorMessage = '无法连接到服务器，请检查网络连接';
            }
            alert(errorMessage);
            
            // 显示错误提示
            const tbody = document.getElementById('applicationRecordsBody');
            tbody.innerHTML = `<tr><td colspan="6" class="text-center text-danger">加载失败: ${errorMessage}</td></tr>`;
            
            // 仍然显示模态框以便用户看到错误信息
            const modal = new bootstrap.Modal(document.getElementById('applicationRecordsModal'));
            modal.show();
        }
    }
    
    // 搜索申请记录
    function searchApplications() {
        const providerName = document.getElementById('appSearchProviderName').value.toLowerCase();
        const status = document.getElementById('appSearchStatus').value;
        
        const rows = document.querySelectorAll('#applicationRecordsBody tr');
        
        rows.forEach(row => {
            const cells = row.cells;
            const nameMatch = cells[0].textContent.toLowerCase().includes(providerName);
            
            let statusMatch = true;
            if (status) {
                const statusText = cells[4].textContent.trim();
                if (status === 'pending' && statusText !== '待审核') statusMatch = false;
                if (status === 'approved' && statusText !== '已批准') statusMatch = false;
                if (status === 'rejected' && statusText !== '已驳回') statusMatch = false;
            }
            
            row.style.display = nameMatch && statusMatch ? '' : 'none';
        });
    }
    
    // 重置申请搜索条件
    function resetApplicationSearch() {
        document.getElementById('appSearchProviderName').value = '';
        document.getElementById('appSearchStatus').value = '';
        
        const rows = document.querySelectorAll('#applicationRecordsBody tr');
        rows.forEach(row => {
            row.style.display = '';
        });
    }
    
    // 查看申请详情
    async function viewApplicationDetail(applicationId) {
        try {
            // 获取申请详情
            const response = await axios.get(`http://localhost:8080/api/provider/application/getApplicationById/${applicationId}`, {
                timeout: 5000
            });
            
            const application = response.data;
            if (!application) {
                alert('未找到相关申请信息');
                return;
            }
            
            // 隐藏申请记录模态框
            const recordsModal = bootstrap.Modal.getInstance(document.getElementById('applicationRecordsModal'));
            recordsModal.hide();
            
            // 填充详情
            document.getElementById('appDetail-providerName').textContent = application.providerName || '-';
            document.getElementById('appDetail-companyType').textContent = application.companyType || '-';
            document.getElementById('appDetail-managerName').textContent = application.managerName || '-';
            document.getElementById('appDetail-managerPhone').textContent = application.managerPhone || '-';
            document.getElementById('appDetail-registeredCapital').textContent = application.registeredCapital ? `${application.registeredCapital}万元` : '-';
            document.getElementById('appDetail-employeeCount').textContent = application.employeeCount || '-';
            document.getElementById('appDetail-establishedYear').textContent = application.establishedYear || '-';
            document.getElementById('appDetail-profile').textContent = application.profile || '-';
            
            let statusText = '';
            let statusClass = '';
            
            if (!application.status) {
                statusText = '待审核';
                statusClass = 'pending';
            } else if (application.approved) {
                statusText = '已批准';
                statusClass = 'approved';
            } else {
                statusText = '已驳回';
                statusClass = 'rejected';
            }
            
            const statusElement = document.getElementById('appDetail-status');
            statusElement.innerHTML = `<span class="status-badge ${statusClass}">${statusText}</span>`;
            
            // 如果已经审核过，显示审核意见，隐藏审批表单
            const reviewContainer = document.getElementById('appDetail-reviewContainer');
            const reviewFormContainer = document.getElementById('appDetail-reviewFormContainer');
            
            if (application.status) {
                try {
                    // 获取审核意见
                    const reviewResponse = await axios.get(`http://localhost:8080/api/provider/application/getReviewById/${applicationId}`, {
                        timeout: 5000
                    });
                    
                    const review = reviewResponse.data;
                    if (review && review.description) {
                        document.getElementById('appDetail-reviewDescription').textContent = review.description;
                        reviewContainer.style.display = 'block';
                    } else {
                        reviewContainer.style.display = 'none';
                    }
                    
                    // 隐藏审批表单
                    reviewFormContainer.style.display = 'none';
                } catch (error) {
                    console.error('获取审核意见失败:', error);
                    reviewContainer.style.display = 'none';
                    reviewFormContainer.style.display = 'none';
                }
            } else {
                // 未审核，显示审批表单，隐藏审核意见
                reviewContainer.style.display = 'none';
                reviewFormContainer.style.display = 'block';
                
                // 设置隐藏的applicationId
                document.getElementById('appApplicationId').value = applicationId;
                
                // 清空表单内容
                document.getElementById('appApprovalStatus').value = '';
                document.getElementById('appDescription').value = '';
                document.getElementById('appInitialRating').value = '3'; // 默认评分
            }
            
            // 显示详情模态框
            const detailModal = new bootstrap.Modal(document.getElementById('applicationDetailModal'));
            detailModal.show();
            
            // 监听详情模态框关闭事件，重新显示记录列表
            document.getElementById('applicationDetailModal').addEventListener('hidden.bs.modal', function () {
                recordsModal.show();
            }, { once: true });
        } catch (error) {
            console.error('获取申请详情失败:', error);
            let errorMessage = '获取申请详情失败，请稍后重试';
            if (error.response) {
                errorMessage += `（状态码: ${error.response.status}）`;
            } else if (error.request) {
                errorMessage = '无法连接到服务器，请检查网络连接';
            }
            alert(errorMessage);
        }
    }
    
    // 审批申请
    function reviewApplication(applicationId) {
        // 直接调用查看详情方法，但会显示审批表单
        viewApplicationDetail(applicationId);
    }
    
    // 提交申请审批
    async function submitApplicationReview() {
        try {
            // 表单验证
            const approvalStatus = document.getElementById('appApprovalStatus').value;
            const description = document.getElementById('appDescription').value.trim();
            const initialRating = document.getElementById('appInitialRating').value;
            const applicationId = document.getElementById('appApplicationId').value;
            
            if (!approvalStatus) {
                alert('请选择处理意见');
                return;
            }
            if (!description) {
                alert('请填写审核意见');
                return;
            }
            if (!initialRating) {
                alert('请填写初始评分');
                return;
            }
            
            // 从localStorage获取审批人工号
            const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}');
            
            // 先获取申请详情
            const applicationResponse = await axios.get(`http://localhost:8080/api/provider/application/getApplicationById/${applicationId}`, {
                timeout: 5000
            });
            
            const application = applicationResponse.data;
            if (!application) {
                alert('未找到相关申请信息');
                return;
            }
            
            // 更新申请状态
            try {
                const updateData = {
                    ...application,
                    status: true,
                    approved: approvalStatus === 'true'
                };
                
                await axios.put('http://localhost:8080/api/provider/application/update', updateData, {
                    timeout: 5000,
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
            } catch (error) {
                console.error('更新申请状态失败:', error);
                alert('更新申请状态失败，请稍后重试');
                return;
            }
            
            // 构建审批数据
            const reviewData = {
                applicationId: parseInt(applicationId),
                approved: approvalStatus === 'true',
                description: description,
                initialRating: parseInt(initialRating)
            };
            
            console.log('提交审批数据:', reviewData);
            
            // 发送审批请求
            const response = await axios.put('http://localhost:8080/api/provider/application/review', reviewData, {
                timeout: 5000,
                headers: {
                    'Content-Type': 'application/json'
                }
            });
            
            alert(response.data || '审批提交成功');
            
            // 关闭详情模态框
            const detailModal = bootstrap.Modal.getInstance(document.getElementById('applicationDetailModal'));
            detailModal.hide();
            
            // 重新加载申请记录
            showAllApplications();
        } catch (error) {
            console.error('提交审批失败:', error);
            let errorMessage = '提交审批失败，请稍后重试';
            if (error.response) {
                const responseData = error.response.data;
                errorMessage = responseData.message || `服务器错误（状态码: ${error.response.status}）`;
            } else if (error.request) {
                errorMessage = '无法连接到服务器，请检查网络连接';
            }
            alert(errorMessage);
        }
    }
    
    // ==================== 供应商投诉管理相关函数 ====================
    
    // 显示所有供应商投诉
    async function showAllComplaints() {
        try {
            const response = await axios.get('http://localhost:8080/api/provider/complaints/getComplaint', {
                timeout: 5000
            });
            
            const complaints = response.data;
            const tbody = document.getElementById('complaintRecordsBody');
            tbody.innerHTML = '';
            
            if (!complaints || complaints.length === 0) {
                tbody.innerHTML = '<tr><td colspan="6" class="text-center">暂无投诉记录</td></tr>';
                return;
            }
            
            complaints.forEach(complaint => {
                const row = document.createElement('tr');
                let statusText = '';
                let statusClass = '';
                
                if (!complaint.status) {
                    statusText = '待审核';
                    statusClass = 'pending';
                } else if (complaint.approved) {
                    statusText = '已批准';
                    statusClass = 'approved';
                } else {
                    statusText = '已驳回';
                    statusClass = 'rejected';
                }
                
                row.innerHTML = `
                    <td>${complaint.providerName || '-'}</td>
                    <td>${complaint.defectiveMaterial || '-'}</td>
                    <td class="description-cell">${complaint.description || '-'}</td>
                    <td>${complaint.complainantJobNumber || '-'}</td>
                    <td><span class="status-badge ${statusClass}">${statusText}</span></td>
                    <td class="action-buttons">
                        <button class="btn btn-sm btn-info" onclick="viewComplaintDetail(${complaint.complaintId})">详情</button>
                        ${!complaint.status ? `<button class="btn btn-sm btn-primary" onclick="reviewComplaint(${complaint.complaintId})">审批</button>` : ''}
                    </td>
                `;
                
                tbody.appendChild(row);
            });
            
            const modal = new bootstrap.Modal(document.getElementById('complaintRecordsModal'));
            modal.show();
        } catch (error) {
            console.error('加载投诉记录失败:', error);
            let errorMessage = '加载投诉记录失败，请稍后重试';
            if (error.response) {
                errorMessage += `（状态码: ${error.response.status}）`;
            } else if (error.request) {
                errorMessage = '无法连接到服务器，请检查网络连接';
            }
            alert(errorMessage);
            
            // 显示错误提示
            const tbody = document.getElementById('complaintRecordsBody');
            tbody.innerHTML = `<tr><td colspan="6" class="text-center text-danger">加载失败: ${errorMessage}</td></tr>`;
            
            // 仍然显示模态框以便用户看到错误信息
            const modal = new bootstrap.Modal(document.getElementById('complaintRecordsModal'));
            modal.show();
        }
    }
    
    // 搜索投诉记录
    function searchComplaints() {
        const providerName = document.getElementById('compSearchProviderName').value.toLowerCase();
        const status = document.getElementById('compSearchStatus').value;
        
        const rows = document.querySelectorAll('#complaintRecordsBody tr');
        
        rows.forEach(row => {
            const cells = row.cells;
            const nameMatch = cells[0].textContent.toLowerCase().includes(providerName);
            
            let statusMatch = true;
            if (status) {
                const statusText = cells[4].textContent.trim();
                if (status === 'pending' && statusText !== '待审核') statusMatch = false;
                if (status === 'approved' && statusText !== '已批准') statusMatch = false;
                if (status === 'rejected' && statusText !== '已驳回') statusMatch = false;
            }
            
            row.style.display = nameMatch && statusMatch ? '' : 'none';
        });
    }
    
    // 重置投诉搜索条件
    function resetComplaintSearch() {
        document.getElementById('compSearchProviderName').value = '';
        document.getElementById('compSearchStatus').value = '';
        
        const rows = document.querySelectorAll('#complaintRecordsBody tr');
        rows.forEach(row => {
            row.style.display = '';
        });
    }
    
    // 查看投诉详情
    async function viewComplaintDetail(complaintId) {
        try {
            // 获取投诉详情
            const response = await axios.get(`http://localhost:8080/api/provider/complaints/getComplaintById/${complaintId}`, {
                timeout: 5000
            });
            
            const complaint = response.data;
            if (!complaint) {
                alert('未找到相关投诉信息');
                return;
            }
            
            // 隐藏投诉记录模态框
            const recordsModal = bootstrap.Modal.getInstance(document.getElementById('complaintRecordsModal'));
            recordsModal.hide();
            
            // 填充详情
            document.getElementById('compDetail-providerName').textContent = complaint.providerName || '-';
            document.getElementById('compDetail-defectiveMaterial').textContent = complaint.defectiveMaterial || '-';
            document.getElementById('compDetail-description').textContent = complaint.description || '-';
            document.getElementById('compDetail-complainant').textContent = complaint.complainantJobNumber || '-';
            
            let statusText = '';
            let statusClass = '';
            
            if (!complaint.status) {
                statusText = '待审核';
                statusClass = 'pending';
            } else if (complaint.approved) {
                statusText = '已批准';
                statusClass = 'approved';
            } else {
                statusText = '已驳回';
                statusClass = 'rejected';
            }
            
            const statusElement = document.getElementById('compDetail-status');
            statusElement.innerHTML = `<span class="status-badge ${statusClass}">${statusText}</span>`;
            
            // 如果已经审核过，显示审核意见，隐藏审批表单
            const reviewContainer = document.getElementById('compDetail-reviewContainer');
            const reviewFormContainer = document.getElementById('compDetail-reviewFormContainer');
            
            if (complaint.status) {
                try {
                    // 获取审核意见
                    const reviewResponse = await axios.get(`http://localhost:8080/api/provider/complaints/getReviewById/${complaintId}`, {
                        timeout: 5000
                    });
                    
                    const review = reviewResponse.data;
                    if (review) {
                        document.getElementById('compDetail-reviewDescription').textContent = review.description || '-';
                        reviewContainer.style.display = 'block';
                    } else {
                        reviewContainer.style.display = 'none';
                    }
                    
                    // 隐藏审批表单
                    reviewFormContainer.style.display = 'none';
                } catch (error) {
                    console.error('获取审核意见失败:', error);
                    reviewContainer.style.display = 'none';
                    reviewFormContainer.style.display = 'none';
                }
            } else {
                // 未审核，显示审批表单，隐藏审核意见
                reviewContainer.style.display = 'none';
                reviewFormContainer.style.display = 'block';
                
                // 设置隐藏的complaintId
                document.getElementById('compComplaintId').value = complaintId;
                
                // 清空表单内容
                document.getElementById('compApprovalStatus').value = '';
                document.getElementById('compReviewDescription').value = '';
                document.getElementById('compRatingDeduction').value = '1'; // 默认扣分
            }
            
            // 显示详情模态框
            const detailModal = new bootstrap.Modal(document.getElementById('complaintDetailModal'));
            detailModal.show();
            
            // 监听详情模态框关闭事件，重新显示记录列表
            document.getElementById('complaintDetailModal').addEventListener('hidden.bs.modal', function () {
                recordsModal.show();
            }, { once: true });
        } catch (error) {
            console.error('获取投诉详情失败:', error);
            let errorMessage = '获取投诉详情失败，请稍后重试';
            if (error.response) {
                errorMessage += `（状态码: ${error.response.status}）`;
            } else if (error.request) {
                errorMessage = '无法连接到服务器，请检查网络连接';
            }
            alert(errorMessage);
        }
    }
    
    // 审批投诉
    function reviewComplaint(complaintId) {
        // 直接调用查看详情方法，但会显示审批表单
        viewComplaintDetail(complaintId);
    }
    
    // 提交投诉审批
    async function submitComplaintReview() {
        try {
            // 表单验证
            const approvalStatus = document.getElementById('compApprovalStatus').value;
            const description = document.getElementById('compReviewDescription').value.trim();
            const ratingDeduction = document.getElementById('compRatingDeduction').value;
            const complaintId = document.getElementById('compComplaintId').value;
            
            if (!approvalStatus) {
                alert('请选择处理意见');
                return;
            }
            if (!description) {
                alert('请填写审核意见');
                return;
            }
            if (!ratingDeduction) {
                alert('请填写评级扣分');
                return;
            }
            
            // 从localStorage获取审批人工号
            const userInfo = JSON.parse(localStorage.getItem('userInfo') || '{}');
            
            // 先获取投诉详情
            const complaintResponse = await axios.get(`http://localhost:8080/api/provider/complaints/getComplaintById/${complaintId}`, {
                timeout: 5000
            });
            
            const complaint = complaintResponse.data;
            if (!complaint) {
                alert('未找到相关投诉信息');
                return;
            }
            
            // 更新投诉状态
            try {
                const updateData = {
                    ...complaint,
                    status: true,
                    approved: approvalStatus === 'true'
                };
                
                await axios.put('http://localhost:8080/api/provider/complaints/update', updateData, {
                    timeout: 5000,
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
            } catch (error) {
                console.error('更新投诉状态失败:', error);
                alert('更新投诉状态失败，请稍后重试');
                return;
            }
            
            // 构建审批数据
            const reviewData = {
                complaintId: parseInt(complaintId),
                approved: approvalStatus === 'true',
                description: description,
                ratingDeduction: parseInt(ratingDeduction)
            };
            
            console.log('提交审批数据:', reviewData);
            
            // 发送审批请求
            const response = await axios.put('http://localhost:8080/api/provider/complaints/review', reviewData, {
                timeout: 5000,
                headers: {
                    'Content-Type': 'application/json'
                }
            });
            
            alert(response.data || '审批提交成功');
            
            // 关闭详情模态框
            const detailModal = bootstrap.Modal.getInstance(document.getElementById('complaintDetailModal'));
            detailModal.hide();
            
            // 重新加载投诉记录
            showAllComplaints();
        } catch (error) {
            console.error('提交审批失败:', error);
            let errorMessage = '提交审批失败，请稍后重试';
            if (error.response) {
                const responseData = error.response.data;
                errorMessage = responseData.message || `服务器错误（状态码: ${error.response.status}）`;
            } else if (error.request) {
                errorMessage = '无法连接到服务器，请检查网络连接';
            }
            alert(errorMessage);
        }
    }
</script>
</body>
</html>